package com.campus.service.impl;

import com.campus.service.TeacherService;
import com.campus.dao.TeacherDao;
import com.campus.dto.TeacherDto;
import com.campus.model.Teacher;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @desc:
 * @author: Tournesol234
 * @date: 2024/11/22 14.41
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    private final TeacherDao teacherDao;

    public TeacherServiceImpl(TeacherDao teacherDao) {
        this.teacherDao = teacherDao;
    }

    @Override
    public int createTeacher(TeacherDto teacherDto) {
        Teacher teacher = new Teacher();
        teacher.setTeacherName(teacherDto.getTeacherName());
        teacher.setSubject(teacherDto.getSubject());
        teacher.setProfession(teacherDto.getProfession());
        teacher.setSchool(teacherDto.getSchool());
        teacher.setIntroduce(teacherDto.getIntroduce());
        teacher.setLoginId(teacherDto.getLoginId());
        return teacherDao.createTeacher(teacher);
    }

    @Override
    public Teacher getTeacherById(int id) {
        return teacherDao.getTeacherById(id);
    }

    @Override
    public List<Teacher> getTeachersByFilter(String subject, String school) {
        return teacherDao.getTeachersByFilter(subject, school);
    }

    @Override
    public int updateTeacher(TeacherDto teacherDto) {
        Teacher teacher = new Teacher();
        teacher.setId(teacherDto.getId());
        teacher.setTeacherName(teacherDto.getTeacherName());
        teacher.setSubject(teacherDto.getSubject());
        teacher.setProfession(teacherDto.getProfession());
        teacher.setSchool(teacherDto.getSchool());
        teacher.setIntroduce(teacherDto.getIntroduce());
        teacher.setLoginId(teacherDto.getLoginId());
        return teacherDao.updateTeacher(teacher);
    }

    @Override
    public int deleteTeacher(int id) {
        return teacherDao.deleteTeacher(id);
    }
}
